package com.jdy.delegate;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class Test {

    public static void main(String[] args) throws IOException {
//        try {
//
//            File file = new File(path);
//            if (file.)
//
//
//                file.createNewFile();
//        } catch (IOException e) {
//            e.printStackTrace();
//            System.out.println("创建失败！");
//        }

//        System.out.println(compressString("bbbac"));

        String path = "F://test//test//|.test";

        createFile(new File(path));
    }


    public static void createFile(File targetFile) throws IOException {
        if (targetFile.exists()) return;

        String path = targetFile.getPath();

        File parentFile = new File(path.substring(0, path.lastIndexOf(File.separatorChar)));

        if (!parentFile.exists()) createFile(parentFile);

        if (! new File(path + File.separatorChar).mkdir()) {
            throw new IOException("文件名无效！  " + path.replace(parentFile.getPath(), ""));
        }
    }


    public static String compressString(String s) {
        if (s.isEmpty()) return s;
        StringBuffer buffer = new StringBuffer(s.charAt(0));
        for (int i = 0, j = 0; i < s.length(); i++) {
            if (s.charAt(i) == s.charAt(j)) {
                if (i == s.length() - 1) i++;
                else continue;
            }

            buffer.append(s.charAt(j)).append(i - j);
            if (i == s.length() - 1) {
                buffer.append(s.charAt(i)).append(1);
            } else {
                j = i;
            }
        }
        return s.length() > buffer.length() ? buffer.toString() : s;
    }
}


